<template>
  <el-container direction="vertical">
    <el-main>
      <h1 style="text-align: center;margin-top: 40px;margin-bottom: 30px" class="bi-bag"> 购物车</h1>
      <p style="text-align: center;margin-bottom: 40px">查看你的购物车</p>
      <div class="row align-items-center" v-for="(items,index) in data" :key="index">
        <div class="col-md-12">
          <Cart :item="data[index]" @getCart="getCart()"></Cart>
        </div>
      </div>
    </el-main>
  </el-container>
</template>

<script>
import Cart from "../components/Cart";
import axios from "axios";
export default {
  name: "Carts",
  components: {Cart},
  data(){
    return{
      data:[]
    }
  },
  methods:{
    getCart(){
      axios.get('http://r44734h518.zicp.vip:41569/cart/showCart?uid='+sessionStorage.getItem("uid")).then(res=>{
        console.log(res.data);
        this.data = res.data;
      })
    }
  },
  created() {
    axios.get('http://r44734h518.zicp.vip:41569/cart/showCart?uid='+sessionStorage.getItem("uid")).then(res=>{
      console.log(res.data);
      this.data = res.data;
    })
  },
  beforeCreate() {
    if (sessionStorage.getItem("isLogin") === null){
      this.$message.warning("请先登录");
      this.$router.push({path:'/login'});
    }
  }
}
</script>

<style scoped>

</style>
